package pers.cnzdy.tutorial.Chapter7_Data.Section3_SQLite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;


public class DBQuizHelper extends SQLiteOpenHelper {

    public static final String CREATE_QUIZ = "create table Quiz ("
            + "id integer primary key autoincrement, "
            + "statement text, "
            + "type text, "
            + "answer text, "
            + "difficulty integer)";

    public static final String CREATE_COURSE = "create table Course ("
            + "id integer primary key autoincrement, "
            + "name text, "
            + "intro text)";

    private Context context;

    public DBQuizHelper(Context context, String name,
                            SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
        this.context = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_QUIZ);
        db.execSQL(CREATE_COURSE);
        Toast.makeText(context, "Create succeeded",
                Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onUpgrade(SQLiteDatabase db,
                          int oldVersion, int newVersion) {
        db.execSQL("drop table if exists Quiz");
        db.execSQL("drop table if exists Course");
        onCreate(db);
    }
}

